class Solution
{
public:
    vector<int> rearrangeArray(vector<int> &nums)
    {
        int n = nums.size();
        vector<int> result(n);
        sort(nums.begin(), nums.end());
        int left = 0;
        int right = n - 1;
        bool sideLeft = true;
        for (int i = 0; i < n; ++i)
        {
            if (sideLeft)
            {
                result[i] = nums[left];
                ++left;
            }
            elses
            {
                result[i] = nums[right];
                --right;
            }
            sideLeft = !sideLeft;
        }
        return result;
    }
};